<?php
include_once '../meihe/common.php';
if ($islogin2 == 1) {
} else exit("<script language='javascript'>window.location.href='./login.php';</script>");
$title = '自助升级权限';
include_once './header.php';
$price = $conf['sjgzyh'] ?? 0;
if ($userrow['power'] == 2) {
    exit("<script language='javascript'>alert('你已是最高权限，无需升级！');window.location.href='./';</script>");
}
?>
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header">
                自助升级权限
            </div>
            <div class="card-body">
                <div class="layui-elem-quote">贵族用户权限: 0成本开通</div>
                <form class="form-horizontal layui-form">
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">升级权限：<span class="badge badge-danger-lighten">账号剩余额：<?php echo round($userrow['rmb'], 2) ?>元</span></label>
                        <select name="power" class="form-control" "power">
                            <option value="2">贵族用户</option>
                        </select>
                    </div>
                    <div class="form-group mb-3">
                        <label for="example-input-normal" style="font-weight: 500">升级价格：</label>
                        <input name="need" class="form-control" value="<?php echo $price ?> 元" disabled>
                    </div>
                    <button type="submit" class="btn btn-block btn-xs btn-outline-success" lay-submit lay-filter="submit_uppower">升 级</button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php
include_once './bottom.php';
?>
<script type="text/javascript">
    layui.use(['form'], function() {
        var form = layui.form;
        form.on('submit(submit_uppower)', function(data) {
            layer.alert('是否要执行当前操作？', {
                icon: 3,
                btn: ['确定', '取消'],
                btn1: function(layero, index) {
                    uppower();
                }
            });
            return false;
        });
    });

    function uppower() {
        var power = $("select[name='power']").val();
        var ii = layer.msg('正在升级中,请稍后...', {
            icon: 16,
            time: 10 * 1000
        });
        $.ajax({
            type: "POST",
            url: "ajax.php?act=uppower",
            data: {
                power: power
            },
            dataType: "json",
            success: function(data) {
                layer.close(ii);
                if (data.code == 0) {
                    layer.msg(data.msg, {
                        icon: 6,
                        end: function(layero, index) {
                            window.location.reload();
                        }
                    });
                } else if (data.code == 1) {
                    layer.msg(data.msg, {
                        icon: 6,
                        end: function(layero, index) {
                            window.location.href = './';
                        }
                    });
                } else {
                    layer.msg(data.msg, {
                        icon: 5
                    });
                }
            },
            error: function(data) {
                layer.msg('服务器错误', {
                    icon: 5
                });
                return false;
            }
        });
        return false;
    };
</script>